<template>
  <!-- 销售详情 -->
  <view class="staDetails">
    <view class="staDetails-nav">
      <u-tabs
        active-color="#000000"
        inactive-color="#999999"
        bar-height="2"
        bar-width="60"
        height="40"
        :list="list"
        :current="current"
        item-width="375"
        @change="tabChange"
      >
      </u-tabs>
    </view>
    <view class="staDetails-bd">
      <template
        v-if="(current && team.length > 0) || (!current && mine.length > 0)"
      >
        <view v-show="!current">
          <template v-for="item in mine">
            <view class="staDetails-bd-item staDetails-bd-mine" :key="item.id">
              <view class="top">
                <view class="top-num">订单号:{{ item.order_num }}</view>
                <view class="top-time">
                  {{ timeFormat(item.createtime, "Y/M/D h:m") }}
                </view>
              </view>
              <view class="bottom">
                <view class="bottom-name">
                  {{ item.order_goods[0].goods_name }}
                </view>
                <view class="bottom-money"> {{ item.money }} </view>
              </view>
            </view>
          </template>
        </view>
        <view v-show="current">
			<view class="staDetails-bd__tips"> 当前暂无相关订单！ </view>
          <!-- <template v-for="(item2, index) in team">
            <view :key="index">
              <template v-for="item3 in item2">
                <template v-if="item3.id">
                  <view
                    class="staDetails-bd-item staDetails-bd-team"
                    :key="item3.id"
                  >
                    <view class="top">
                      <view class="top-num">订单号:{{ item3.order_num }}</view>
                      <view class="top-time">
                        {{ timeFormat(item3.createtime, "Y/M/D h:m") }}
                      </view>
                    </view>
                    <view class="bottom">
                      <view class="bottom-name">
                        {{ item3["team_" + state][0].goods_name }}
                      </view>
                      <view class="bottom-money">
                        {{ item3.money }}
                      </view>
                    </view>
                  </view>
                </template>
              </template>
            </view>
          </template> -->
        </view>
      </template>
      <template v-else>
        <view class="staDetails-bd__tips"> 当前暂无相关订单！ </view>
      </template>
    </view>
  </view>
</template>

<script>
import { incomeDetails } from "@/utils/api";
import { formatTime } from "@/utils/time";
export default {
  computed: {
    // goodsName(){
    // 	if(this.team.length>0){
    // 		return
    // 	}
    // }
  },
  data() {
    return {
      state: "",
      team: [],
      mine: [],
      content: [],
      list: [
        {
          name: "我的",
        },
        {
          name: "团队",
        },
      ],
      current: 0,
    };
  },
  onLoad({ state }) {
    this.state = state;
    this.initInfo();
  },
  onReady() {
    let obj = {
      today: "今日",
      week: "本周",
      month: "本月",
      last_month: "上月",
    };
    uni.setNavigationBarTitle({
      title: obj[this.state] + "收益",
    });
  },
  methods: {
    initInfo() {
      incomeDetails({
        state: this.state,
      }).then((resp) => {
        console.log(resp);
        if (resp.code == 200) {
          // this.list = resp.data;
          this.team = resp.data["team_" + this.state];
          // for (let i = 0; i < this.team.length; i++) {
          //   this.team[i].filter((item) => item.id);
          // }
          this.team.filter((item) => {
            return item.filter((children) => children.id);
          });
          console.log("this.team", this.team);

          this.mine = resp.data[this.state];
          // this.content = this.current ? this.team : this.mine;
        }
      });
    },
    tabChange(index) {
      this.current = index;
      // this.content = this.current ? this.team : this.mine;
    },
    timeFormat(time, str) {
      return formatTime(time, str);
    },
  },
};
</script>
<style>
page {
  background-color: #f7f7f7;
}
</style>
<style lang="scss">
.staDetails {
  width: 100%;

  &-bd {
    width: 100%;
    box-sizing: border-box;
    padding: 20rpx;

    &-item {
      width: 100%;
      background-color: #ffffff;
      box-sizing: border-box;
      padding: 15rpx;

      .top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10rpx 0;
        position: relative;
        &::before {
          content: "";
          width: 100%;
          height: 1rpx;
          position: absolute;
          left: 0;
          bottom: 0;
          transform: scaleY(0.5);
          border-top: 1rpx solid rgba(202, 202, 202, 0.5);
        }
      }
      .bottom {
        display: flex;
        align-items: center;
        justify-content: space-between;
        &-name {
          width: calc(100% - 300rpx);
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
        }
        &-money {
          font-size: 30rpx;
          font-weight: bold;
          color: #cd8544;
          width: 200rpx;
          text-align: right;
        }
      }
    }
    &-mine {
      border-radius: 12rpx;
      margin-bottom: 20rpx;
    }
    &-team {
      margin-bottom: 20rpx;
    }
    &__tips {
      width: 100%;
      padding: 20rpx 0;
      text-align: center;
    }
  }
}
</style>
